package com.ruoyi.web.core.redpacket;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;

import java.util.SortedMap;
import java.util.TreeMap;

@Slf4j
public class TransferToChange extends Transfer {

    private static final String TRANSFERS_PAY = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";


    public String wxSendWallet(String merchantId,String secret, String appId, String openId, String orderId, String actName, int amount) {

        String data = null;
        try {

            String nonceStr = RandomStringUtils.randomAlphabetic(32);

            SortedMap parameters = new TreeMap();

            parameters.put("mch_appid", appId);

            parameters.put("mchid", merchantId);

            parameters.put("nonce_str", nonceStr);

            parameters.put("partner_trade_no", orderId);

            parameters.put("openid", openId);

            parameters.put("check_name", "NO_CHECK");

            parameters.put("amount", amount);

            parameters.put("spbill_create_ip", "139.224.103.17");

            parameters.put("desc", actName);//签名

            parameters.put("sign", generateSignature(parameters, secret));

            data = mapToXml(parameters);

            log.info("xml:{}", data);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return data;
    }

    @Override
    protected String getUrl() {
        return TRANSFERS_PAY;
    }

    @Override
    protected String getCert() {
        return "cert/apiclient_cert.p12";
    }



}
